package com.spica.spicaschool.ui.sport

import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
import androidx.navigation.findNavController
import com.kongzue.dialogx.dialogs.MessageDialog
import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener
import com.kongzue.dialogx.util.TextInfo
import com.spica.spicaschool.R
import com.spica.spicaschool.base.BaseFragment
import com.spica.spicaschool.databinding.FragmentSportBinding
import com.spica.spicaschool.ui.main.MainFragmentDirections


/**
 * 运动页
 */
class SportFragment : BaseFragment<FragmentSportBinding>() {


  override fun setupViewBinding(
    inflater: LayoutInflater,
    container: ViewGroup?
  ): FragmentSportBinding = FragmentSportBinding.inflate(layoutInflater, container, false)

  override fun init() = initView()


  private fun initView() {
    viewBinding.viewpager.adapter =
      SportFragmentAdapter(childFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)
    viewBinding.tablayout.setupWithViewPager(viewBinding.viewpager)
    val navigationController = requireActivity().findNavController(R.id.fragment_container_view)
    val messageDialog =
      MessageDialog("Spica 校园", "管理您的账号信息", "管理账号信息", "取消", "退出登录")
        .setButtonOrientation(LinearLayout.VERTICAL)

    messageDialog.okTextInfo = TextInfo().setFontColor(
      Color.parseColor("#EB5545")
    )

    messageDialog.okButtonClickListener =
      OnDialogButtonClickListener { _, _ ->
        navigationController.navigate(MainFragmentDirections.actionHomeToSettingAccount())
        false
      }
    viewBinding.btnMenu.setOnClickListener {
      navigationController.navigate(MainFragmentDirections.actionHomeToSetting())
    }
    viewBinding.ivAvatar.setOnClickListener {
      messageDialog.show()
    }
  }

}
